package cn.wolfcode.service.impl;

import cn.wolfcode.domain.Exam;
import cn.wolfcode.domain.Question;
import cn.wolfcode.mapper.ExamMapper;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IExamService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ExamServiceImpl implements IExamService {

    @Autowired
    private ExamMapper examMapper;


    @Override
    public void save(Exam exam) {
        examMapper.insert(exam);
    }

    @Override
    public void delete(Long id) {
        examMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Exam exam) {
        examMapper.updateByPrimaryKey(exam);
    }

    @Override
    public Exam get(Long id) {
        return examMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Exam> listAll() {
        return examMapper.selectAll();
    }

    @Override
    public List<Question> selectQuestion(Integer questionType,Integer questionAmount) {
        List<Question>questions = examMapper.selectQuestion(questionType, questionAmount);
        return questions;
    }

    @Override
    public void insertTitleAndTime(Exam exam) {
        examMapper.insertTitleAndTime(exam);
    }

    //插入随机问题到exam_question表中
    public void insertRandomQuestion(List<Question> singleQuestion,Long examId,Integer everyQuestionScore) {
        examMapper.insertRandomQuestion(singleQuestion,examId,everyQuestionScore);
    }

    //把所有的数据查询封装到exam对象中
    public Exam selectExamPaperByExamId(Long id) {
        return  examMapper.selectExamPaperByExamId(id);
    }


}
